<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <!-- <img src="../assets/logo.png" alt=""> -->
        <span>安徽大学理工学院</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>

      <!-- <div> -->
      <!-- <img src="../assets/logo.png" alt=""> -->
      <!-- <span>安徽理工学院</span> -->
      <!-- </div> -->
      <!-- <el-button type="info" @click="logout">退出</el-button> -->
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="asideWidth">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 -->
        <el-menu :unique-opened="true" :collapse-transition="false" :collapse="isCollapse" :router="true" :default-active="navActive">
          <!-- 导航一区域 -->
          <el-submenu :index="item.id+''" v-for="(item,index) in menulist" :key="index">
            <!-- 导航一 -->
            <template slot="title">
              <i :class="iconsObj[125]"></i>
              <span>{{item.authName}}</span>
            </template>
            <!-- 导航一子菜单 -->
            <el-menu-item @click="saveNavState('/home/'+subItem.path)" :index="'/home/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <template slot="title">{{subItem.authName}}</template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧主体 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import api from "@/api/api"
  export default {
    data() {
      return {
        menulist: [
          {
            "id": 1,
            "authName": "用户管理",
            "path": null,
            "children": [
              {
                "id": 101,
                "authName": "用户管理-1",
                "path": "user",
                "children": []
              },
              {
                "id": 102,
                "authName": "用户管理-2",
                "path": "user1",
                "children": []
              }
            ]
          },
           {
            "id": 2,
            "authName": "图像识别",
            "path": null,
            "children": [
              {
                "id": 201,
                "authName": "图像识别-1",
                "path": "img",
                "children": []
              },
              {
                "id": 202,
                "authName": "图像识别-2",
                "path": "img1",
                "children": []
              }
            ]
          }
        ],
        iconsObj: {
          '125': 'el-icon-s-custom',
          // '103':'el-icon-s-check',
          // '101':'el-icon-s-goods',
          // '102':'el-icon-s-order',
          // '145':'el-icon-s-data'
        },
        // 是否折叠
        isCollapse: false,
        asideWidth: '200px',
        //当前激活二级菜单
        navActive: ''
      }
    },
    created() {
      // this.getMenuList()
      this.navActive = window.sessionStorage.getItem('active')
    },
    methods: {
      logout() {
        // 清空token
        // window.sessionStorage.clear()
        // 编程式导航到login
        // this.$router.push('/login')
        api.jumpPage("Login")
      },
      // 获取所有菜单
      // async getMenuList() {
      //   const  {data:res} = await this.$http.get('menus')
      //   if(res.meta.status !== 200) return this.$message.error(res.meta.msg)
      //   this.menulist = res.data
      //   // console.log(res)
      //   // console.log(this.menulist)
      // },
      // 菜单的折叠与展开
      toggleCollapse() {
        this.isCollapse = !this.isCollapse
        if (this.isCollapse) {
          this.asideWidth = '64px'
        } else {
          this.asideWidth = '200px'
        }
      },
      // 保存二级菜单激活状态
      saveNavState(active) {
        window.sessionStorage.setItem('active', active)
        this.navActive = active
      }
    }
  }
</script>

<style lang="less" scoped="scoped">
.home-container {
  height: 100%;
}
.el-header,
.el-footer {
  background-color: #393d49;
  color: #bcbdbf;
  text-align: center;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  padding-left: 5;
  align-items: center;
  font-size: 20px;
  div {
    display: flex;
    align-items: center;
    span {
      margin-left: 15px;
    }
  }
}
.el-aside {
  // background-color: #20222a;
  // color: #bcbdbf;
  // text-align: center;
  // line-height: 200px;
  .el-menu {
    border-right: none;
  }
}

.el-main {
  background-color: #f2f2f2;
  color: #000;
  // text-align: center;
  // line-height: 160px;
}
.el-header img {
  width: 45px;
}
.toggle-button {
  background-color: #393d49;
  text-align: center;
  font-size: 10px;
  height: 24px;
  line-height: 24px;
  color: #bcbdbf;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>